#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""

@Time   :2025/8/5 下午9:50
@Author :zengjiahao1989@gmail.com
@File   :2.Model批处理.py
"""
import os
from datetime import datetime

import dotenv
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()

# 1 编排prompt
prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "你是一个OpenAi开发的聊天机器人，请根据用户的提问进行回复，当前的时间为：{now}"),
        ("human", "{query}")
    ]
).partial(now=datetime.now())

# 2.创建大语言模型
llm = ChatOpenAI(
    model_name="kimi-k2-0711-preview",
    openai_api_key=os.getenv("OPENAI_API_KEY"),
    openai_api_base=os.getenv("OPENAI_API_BASE"),
)

ai_messages = llm.batch([
    prompt.invoke({"query": "你好，你是？"}),
    prompt.invoke({"query": "请讲一个关于程序员的冷笑话"})
])

for ai_message in ai_messages:
    print(ai_message.content)
    print("========")
